home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / VideoToolbox / VideoToolboxSources / GetClicks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-19  |  1.6 KB  |  52 lines  |  [TEXT/CWIE]

  1. /*
  2. GetClicks.c
  3. waits for a mouse click, and then counts clicks (e.g. double-click, triple-click). Each
  4. click must arrive within the acceptable double-click time of the previous,
  5. as set in the Control Panel. Returns the number of clicks, 1 or more.
  6. HISTORY:
  7. 4/30/88 dgp    wrote it
  8. 3/31/90    dgp    cleaned up code and documentation.
  9. 8/24/91    dgp    Made compatible with THINK C 5.0.
  10. 3/30/91    dgp    use SndStop1() instead of obsolete Sound Driver.
  11. 1/25/93 dgp removed obsolete support for THINK C 4.
  12. 4/29/95 dgp added GetNextEventOrQuit(), so that we can abort at any time by hitting Command-.
  13. 6/18/95 dgp changed abort() to exit(1) for better compatibility with CW atexit().
  14. */
  15. #include "VideoToolbox.h"
  16. short GetNextEventOrQuit(int mask,EventRecord *eventPtr);
  17.  
  18. short GetClicks(void)
  19. {
  20.     long ticks;
  21.     EventRecord event;
  22.     short clicks;
  23.  
  24.     clicks=0;
  25.     while(!GetNextEventOrQuit(mDownMask,&event)) ;
  26.     SndStop1();    /* Stop sound on first click */
  27.     clicks++;
  28.     ticks=TickCount()+GetDblTime();
  29.     while(!GetNextEventOrQuit(mUpMask,&event)) ;
  30.     while(TickCount() < ticks)    /* wait as long a possible for another click */
  31.         if(GetNextEventOrQuit(mDownMask,&event)){
  32.             clicks++;
  33.             ticks=TickCount()+GetDblTime();
  34.             while(!GetNextEventOrQuit(mUpMask,&event)) ;
  35.         }
  36.     return clicks;
  37. }
  38.  
  39. short GetNextEventOrQuit(int mask,EventRecord *eventPtr)
  40. {
  41.     if(GetNextEvent(mask|keyDownMask,eventPtr))switch(eventPtr->what){
  42.     case keyDown:
  43.         if((eventPtr->message&charCodeMask)=='.' && eventPtr->modifiers&cmdKey){
  44.             printf("\n“Command-.” EXITING.\n");
  45.             exit(1);
  46.         }
  47.         return (mask&keyDownMask)!=0;
  48.     default:
  49.         return 1;
  50.     }else return 0;
  51. }
  52.